module.exports = {
	/**
	 * 查询角色列表
	 * @url client/wechat/selects/pub/selects 前端调用的url参数地址
	 * 表名
	 * @dbName 查询的表的名称
	 * data 请求参数 说明
	 * @param {Number}         pageIndex 当前页码
	 * @param {Number}         pageSize  每页显示数量
	 * @param {Array<Object>}  sortRule  排序规则
	 * @param {object}         formData  查询条件数据源
	 * @param {Array<Object>}  columns   查询条件规则
	 * res 返回参数说明
	 * @param {Number}         code      错误码，0表示成功
	 * @param {String}         msg       详细信息
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let res = { code: 0, msg: '' };
		// 业务逻辑开始-----------------------------------------------------------
		let plaform = ''
		if(originalParam.context.PLATFORM === 'mp-weixin'){
			plaform = 'wx'
		}
		res.msg = "缓存查询"
		var cache = await vk.globalDataCache.get(plaform+'_center');
		if(cache) return cache
		
		// 下载配置
		let client = await vk.baseDao.findByWhereJson({
			dbName: 'bus-wx-config',
			whereJson: {
				config_key: plaform+'_config'
			}
		})
		let verify
		if(client && client.verify) verify = 0
		
		
		// 标签
		let tags = await vk.baseDao.selects({
			dbName: 'bus-wx-tags',
			pageIndex: 1,
			pageSize: 20,
			whereJson: {
				hot: 1
			},
		});
		res.tags = tags
		
		// 壁纸分类
		let bzcate = await vk.baseDao.selects({
			dbName: 'bus-wx-category',
			pageIndex: 1,
			pageSize: 20,
			whereJson: {
				mode: 0,
				status: 1,
				verify
			},
			sortArr: [{name: '_add_time', type: 'asc'}]
		});
		res.bzcate = bzcate
		
		// 头像分类
		let txcate = await vk.baseDao.selects({
			dbName: 'bus-wx-category',
			pageIndex: 1,
			pageSize: 20,
			whereJson: {
				mode: 1,
				status: 1,
				verify
			},
			sortArr: [{name: '_add_time', type: 'asc'}]
		});
		res.txcate = txcate
		
		// 表情包分类
		let bqbcate = await vk.baseDao.selects({
			dbName: 'bus-wx-category',
			pageIndex: 1,
			pageSize: 20,
			whereJson: {
				mode: 5,
				status: 1,
				verify
			},
			sortArr: [{name: '_add_time', type: 'asc'}]
		});
		res.bqbcate = bqbcate
		
		await vk.globalDataCache.set(plaform+'_center', res, 0);
		res.msg = "数据库查询"
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}

}